package org.room402.chat.process;

import lombok.RequiredArgsConstructor;
import org.reactivestreams.Publisher;
import org.room402.entity.chat.MessageEvent;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.socket.WebSocketSession;
import reactor.core.publisher.Mono;

import java.util.List;

@Component
@RequiredArgsConstructor
public class MessageProcessManager {
    private final List<MessageProcess> messageProcesses;

    public Publisher<Void> process(MessageEvent messageEvent, WebSocketSession session) {
        for (MessageProcess process : messageProcesses) {
            if (process.actionMatch(messageEvent, session)) {
                if (process.rejectMatch(messageEvent, session)) {
                    return process.reject(messageEvent, session);
                }
                return process.process(messageEvent, session);
            }
        }
        return Mono.empty();
    }


}
